#include <cassert>
#include <fstream>

#include "../tools/Log.h"
#include "../tools/StringTokenizer.h"
#include "BuildingType.h"
#include "GameControl.h"

using namespace std;

BuildingType::BuildingType()
: name()
, required_resources()
, producer_of()
, initial_health(0)
, id(-1)
{ }

BuildingType::BuildingType(int id, string name, int initial_health, vector <Resource> required_resources) :
	name(name), required_resources(required_resources), producer_of(), initial_health(initial_health), id(id) { }

void BuildingType::produces(UnitType *ut)
{
	producer_of.push_back(ut);
}

void BuildingType::load_from_file(string file_name)
{
	char line[255];
	ifstream fin(file_name.c_str());
	
	if (!fin) {
		lout << "WARNING: BuildingType - Unable to load building type config file: \"" << file_name << "\"" << endl;	
		return;
	}
	
	while (fin.getline(line, 255))
	{
		if (line[0] == '#') continue; 
		
		unsigned id, initial_health;
		char name[255], resource_requirements[255];
		
		sscanf(line, "%u %s %u %s", &id, name, &initial_health, resource_requirements);
		
		//BuildingType *bt = new BuildingType(id, name, initial_health, Resource::load_from_string(game, resource_requirements));
		//game->add_building_type(bt);
	}
	
	fin.close();
}
